package com.example.demo.controller;

import com.example.demo.Request.OrderQuest;
import com.example.demo.model.Item;
import com.example.demo.model.Order;
import com.example.demo.service.IOrderService;
import com.example.demo.service.lmp.ProductServicelmp;
import com.example.demo.vo.RestResultVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/order")
@Api(tags = "订单操作")
@Slf4j
public class OrderController {

    @Autowired
    IOrderService orderService;

    @PostMapping("/ordercreate")
    @ApiOperation("创建订单")
    public RestResultVo<Order> listRestResultVo(@RequestBody OrderQuest orderQuest){
        log.info("Received OrderQuest: {}", orderQuest); // 添加日志以查看接收到的OrderQuest对象
        Order order = orderService.createOrder(orderQuest.getItems(), orderQuest.isVIP());
        return RestResultVo.ok(order);
    }


    @GetMapping("/cancel")
    @ApiOperation("取消订单")
    public RestResultVo<Order> cancel(String orderId){
        String order =orderService.cancelOrder(orderId);
        // 获取取消后的订单详情
        Order orderDetails = orderService.getOrderDetails(orderId);
        return  RestResultVo.ok(orderDetails);
    }


}
